#ifndef __DUMPSENDER_H__
#define __DUMPSENDER_H__

#include "port.h"
#include "ratelimitconn.h"
#include "timer.h"
#include "message.h"
#include "congestmonitor.h"


class DumpSender : public IConnListener, public INTDTimerListener//, public MessageHandler
{
public:
	DumpSender(IConnection::PROTO_TYPE type, const SocketAddress& remote_addr, size_t pkt_len=1000, uint32 limit=UINT_MAX);
	virtual ~DumpSender();

	void SetRateLimit(uint32 limit);//Bytes/sec

	void SetPktlen(size_t ptk_len);

	//////////////////////////////////////////////////////////////////////////
	//Only active connection for sender
	virtual void OnCreated(IConnection* pConn) {}

	//Let's wait for writable event
	virtual void OnConnected(IConnection* pConn) {}

	//Not need processing
	virtual void OnReadPacket(IConnection* pConn, const char* data, size_t size) {}

	virtual void OnWritable(IConnection* pConn, bool writable);

	virtual void OnClose(IConnection* pConn, int err) {}
	virtual void OnError(IConnection* pConn, int err);

	virtual void OnDestroy(IConnection* pConn); 

	//////////////////////////////////////////////////////////////////////////
	//virtual void OnMessage(Message *pmsg);

	virtual void OnTimer(NTDTimer* pTimer);

	void SendOutDump();

private:
	Port* port_;

	RatelimitConn * conn_;
	Connection * real_conn_;
	CongestMonitor * cc_monitor_;

	NTDTimer tick_;

	byte* dump_data_;
	size_t payload_len_;
};

#endif//__DUMPSENDER_H__